package com.bestvike.stone.core.util.area;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.ToString;

import java.util.Collection;

/**
 * 市级行政区
 * Created by 许崇雷 on 2018-07-28.
 */
@Data
@EqualsAndHashCode(exclude = {"countyCollection", "province"})
@ToString(exclude = {"countyCollection", "province"})
public final class City implements IArea {
    @JSONField(ordinal = 1)
    private final String code;
    @JSONField(ordinal = 2)
    private final String name;
    @JSONField(ordinal = 3)
    private final Collection<County> countyCollection = new CountyCollection(this);
    @Setter(AccessLevel.PACKAGE)
    @JSONField(serialize = false, deserialize = false)
    private transient Province province;

    public City(String code, String name, Collection<County> countyCollection) {
        this.code = code;
        this.name = name;
        if (countyCollection != null)
            this.countyCollection.addAll(countyCollection);
    }

    public CountyCollection getCountyCollection() {
        return (CountyCollection) this.countyCollection;
    }
}
